package com.hunliji.monitor.manager.rest;

import com.alibaba.fastjson.JSONObject;
import com.hunliji.monitor.manager.rest.model.feishu.*;
import com.hunliji.monitor.manager.rest.param.FeiShuObtainAccessTokenRestParam;
import com.hunliji.monitor.manager.rest.param.FeiShuSendMsgRestParam;
import com.hunliji.monitor.manager.rest.param.FeiShuUrgentAppRestParam;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

/**
 * 对接飞书的接口
 * @author hunliji
 */
@FeignClient( name = "fei-shu",url = "https://open.feishu.cn", path = "/open-apis", configuration = FeignAutoConfiguration.class)
public interface FeiShuRest {
    /**
     * 获取 token
     * @param feiShuObtainAccessTokenRestParam
     * @return
     */
    @PostMapping("/auth/v3/tenant_access_token/internal")
    FeiShuObtainAccessTokenListRestModel obtainToken(@RequestBody FeiShuObtainAccessTokenRestParam feiShuObtainAccessTokenRestParam);

    /**
     * 获取群组
     * @param pageToken：下一页的token
     * @param pageSize：一页大小
     * @param authorization：token
     * @return
     */
    @GetMapping("/im/v1/chats")
    FeiShuListRestModel<FeiShuObtainChatGroupRestModel> obtainChatGroup(@RequestParam("page_token") String pageToken, @RequestParam("page_size") Integer pageSize,
                                                                        @RequestHeader("Authorization") String authorization);

    /**
     * 获取飞书群组成员
     * @param chatId:群组id
     * @param memberIdType：群成员 用户 ID 类型
     * @param pageToken：下一页的token
     * @param pageSize：一页大小
     * @param authorization：token
     * @return
     */
    @GetMapping("im/v1/chats/{chat_id}/members")
    FeiShuListRestModel<FeiShuObtainChatGroupMemberRestModel> obtainChatGroupMember(@PathVariable("chat_id") String chatId,
                                                                                    @RequestParam("member_id_type") String memberIdType,
                                                                                    @RequestParam("page_token") String pageToken,
                                                                                    @RequestParam("page_size") Integer pageSize,
                                                                                    @RequestHeader("Authorization") String authorization);

    /**
     * 飞书消息发送
     * @param receiveIdType
     * @param feiShuSendMsgRestParam
     * @param authorization
     * @return
     */
    @PostMapping("/im/v1/messages")
    FeiShuRestModel<FeiShuSendMsgRestModel> sendMsg(@RequestParam("receive_id_type") String receiveIdType, FeiShuSendMsgRestParam feiShuSendMsgRestParam,
                                                    @RequestHeader("Authorization") String authorization);

    /**
     * 应用内消息加急
     * @param messageId
     * @return
     */
    @RequestMapping(value = "/im/v1/messages/{message_id}/urgent_app",method = RequestMethod.PATCH)
    FeiShuRestModel<FeiShuUrgentAppRestModel> urgentApp(@PathVariable("message_id") String messageId, @RequestBody FeiShuUrgentAppRestParam urgentAppRestParam,
                                                        @RequestParam("user_id_type") String userIdType,@RequestHeader("Authorization") String authorization);

    /**
     * 发送电话加急
     * @param messageId
     * @return
     */
    @RequestMapping(value = "/im/v1/messages/{message_id}/urgent_phone",method = RequestMethod.PATCH)
    FeiShuRestModel<FeiShuUrgentAppRestModel> urgentPhone(@PathVariable("message_id") String messageId,
                                                           @RequestBody FeiShuUrgentAppRestParam urgentAppRestParam,
                                                           @RequestParam("user_id_type") String userIdType,
                                                           @RequestHeader("Authorization") String authorization);

    /**
     * 获取单个用户信息
     * @param userId
     * @param userIdType
     * @param departmentIdType
     * @param authorization
     * @return
     */
    @GetMapping("/contact/v3/users/{user_id}")
    FeiShuRestModel<FeishuUserInfoResultRestModel> getUserInfo(@PathVariable("user_id") String userId,
        @RequestParam("user_id_type") String userIdType,
        @RequestParam("department_id_type") String departmentIdType,
        @RequestHeader("Authorization") String authorization);


    @PostMapping("/bot/v2/hook/{robotToken}")
    FeiShuRestModel<JSONObject> sendRobotMessage(@PathVariable("robotToken") String robotToken,
                                             @RequestBody JSONObject param);

}
